import { ChatMessageType } from "@/pages/room/components/chat/chat-message.ts";
import type HistoryUserStore from "../../HistoryUserStore.ts";
import type { ReactiveData } from "../../model";
import type { ServerEventListener } from "../ws.ts";


export function createUserJoinListener(
    data: ReactiveData,
    historyUserStore: HistoryUserStore
): ServerEventListener<"user.join"> {

    return function (details) {
        historyUserStore.add(details.user);
        data.room?.users?.push(details.user);

        data.chats.push({
            type: ChatMessageType.SYSTEM,
            metadata: {},
            content: `${details.user.nickname} 加入房间`
        });
    }

}